
package com.eworking.eim.message.body;

import java.io.File;

import com.eworking.eim.util.EIMLog;
import com.eworking.eim.util.PathUtil;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

public class VideoMessageBody extends FileMessageBody {
    
    /** 视频长度 */
    public int length = 0;
    
    /** 缩略图地址 */
    public String thumbnailUrl;
    
    /** 本地缩略图地址 */
    public String localThumb;
    
    /**   */
    public String thumbnailSecret = null;
    
    /** 文件大小 */
    public long file_length = 0;
    
    public static final Parcelable.Creator<VideoMessageBody> CREATOR = new Parcelable.Creator<VideoMessageBody>() {
        
        @Override
        public VideoMessageBody createFromParcel(Parcel parcel) {
            return new VideoMessageBody(parcel);
        }
        
        @Override
        public VideoMessageBody[] newArray(int size) {
            return new VideoMessageBody[size];
        }
    };
    
    public VideoMessageBody(File file, String localThumb, int length, long fileLength) {
        if (!(file.exists()))
            throw new IllegalArgumentException("video file doesn't exists:" + file.getAbsolutePath());
        if (!(new File(localThumb).exists()))
            throw new IllegalArgumentException("video thumb doesn't exists:" + localThumb);
        this.localUrl = file.getAbsolutePath();
        this.fileName = file.getName();
        this.localThumb = localThumb;
        this.length = length;
        this.file_length = fileLength;
        EIMLog.d("videomsg", "create video,message body for:" + file.getAbsolutePath());
    }
    
    public VideoMessageBody(String fileName, String remoteUrl, String thumbnailUrl, int length) {
        this.fileName = fileName;
        this.remoteUrl = remoteUrl;
        this.thumbnailUrl = thumbnailUrl;
        this.length = length;
    }
    
    public String getThumbnailUrl() {
        return this.thumbnailUrl;
    }
    
    public void setThumbnailUrl(String paramString) {
        this.thumbnailUrl = paramString;
    }
    
    public long getVideoFileLength() {
        return this.file_length;
    }
    
    public void setVideoFileLength(long paramLong) {
        this.file_length = paramLong;
    }
    
    public void setLocalThumb(String paramString) {
        this.localThumb = paramString;
    }
    
    /**
     * 获取本地缩略图地址
     * 
     * @return
     */
    public String getLocalThumb() {
        if ((!(TextUtils.isEmpty(this.localThumb))) && (new File(this.localThumb).exists())) {
            return this.localThumb;
        }
        if ((!(TextUtils.isEmpty(this.thumbnailUrl))) && (!(this.thumbnailUrl.equals("null")))) {
            String strName =
                "th" + this.thumbnailUrl.substring(this.thumbnailUrl.lastIndexOf("/") + 1, this.thumbnailUrl.length());
            File file = new File(PathUtil.getInstance().getVideoPath(), strName);
            if (!(file.exists()))
                return file.getAbsolutePath();
        }
        if ((!(TextUtils.isEmpty(this.localUrl))) && (new File(this.localUrl).exists())) {
            String strName = "th" + new File(this.localUrl).getName();
            File file = new File(PathUtil.getInstance().getVideoPath(), strName);
            if (file.exists())
                return file.getAbsolutePath();
        }
        return null;
    }
    
    public int getLength() {
        return this.length;
    }
    
    public String toString() {
        return "video:" + this.fileName + ",localUrl:" + this.localUrl + ",remoteUrl:" + this.remoteUrl
            + ",thumbnailUrl:" + this.thumbnailUrl + ",length:" + this.length;
    }
    
    public int describeContents() {
        return 0;
    }
    
    public void writeToParcel(Parcel parcel, int paramInt) {
        parcel.writeString(this.fileName);
        parcel.writeString(this.localUrl);
        parcel.writeString(this.remoteUrl);
        parcel.writeString(this.thumbnailUrl);
        parcel.writeString(this.localThumb);
        parcel.writeInt(this.length);
        parcel.writeLong(this.file_length);
    }
    
    private VideoMessageBody(Parcel parcel) {
        this.fileName = parcel.readString();
        this.localUrl = parcel.readString();
        this.localThumb = parcel.readString();
        this.remoteUrl = parcel.readString();
        this.thumbnailUrl = parcel.readString();
        this.length = parcel.readInt();
        this.file_length = parcel.readLong();
    }
    
    public void setThumbnailSecret(String paramString) {
        this.thumbnailSecret = paramString;
    }
    
    public String getThumbnailSecret() {
        return this.thumbnailSecret;
    }
}
